package com.weather.job;

import java.util.ArrayList;
import java.util.List;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;

import com.weather.service.WeatherDataCollectionService;
import com.weather.vo.City;

/**
 * @Description 天气数据同步 job
 *
 * @author 堆堆堆
 * @date 2018年5月31日 下午2:55:58
 */
public class WeatherDataSyncJob extends QuartzJobBean {

	private final static Logger logger = LoggerFactory.getLogger(WeatherDataSyncJob.class);

	@Autowired
	private WeatherDataCollectionService weatherDataCollectionService;

	@Override
	protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
		logger.info("Weather Data Sync Job. Start！");

		// 获取城市 id 列表
		// TODO 改为由城市数据 API 微服务来提供数据
		List<City> cityList = null;
		try {

			// TODO 改为由城市数据 API 微服务来提供数据
			cityList = new ArrayList<>();
			City city = new City();
			city.setCityId("101280601");
			cityList.add(city);

		} catch (Exception e) {
			logger.error("Exception!", e);
		}

		for (City city : cityList) {
			String cityId = city.getCityId();
			logger.info("Weather Data Sync Job，cityId：" + cityId);

			weatherDataCollectionService.syncDataByCityId(cityId);
		}

		logger.info("Weather Data Sync Job. End！");

	}

}